package edu.whu.rose.clock.kps.algorithm.blinks.search;

import com.sleepycat.je.DatabaseException;

import edu.whu.rose.clock.kps.algorithm.blinks.index.BilevelIndexDB;
import edu.whu.rose.clock.kps.algorithm.blinks.index.BlockKeyword;
import edu.whu.rose.clock.kps.algorithm.blinks.index.KNEntry;

public class KNCursor extends Cursor {

	private final String keyword;
	
	public KNCursor(int block, String keyword, BilevelIndexDB bidb) {
		super(true, block, bidb);
		this.keyword = keyword;
		BlockKeyword bk = new BlockKeyword(block, keyword);
		try {
			list = bidb.getFromKeywordVertex(bk);
			if (list == null) {
				System.err.println("Error: cannot find KN list");
				System.exit(1);
			}
		}
		catch (DatabaseException ex) {
			ex.printStackTrace();
		}
	}

	public int getFirst() {
		return ((KNEntry)list[pos]).getFirst();
	}

	public int getKnode() {
		return ((KNEntry)list[pos]).getKnode();
	}

	public int getNode() {
		return ((KNEntry)list[pos]).getNode();
	}

	public double getDistance() {
		return ((KNEntry)list[pos]).getDistance();
	}

	public double peek() {
		return ((KNEntry)list[pos + 1]).getDistance();
	}

}
